import { msOfDay } from "./constants"
import { dateFormat } from "./dateFormat"
import { dateParse } from "./dateParse"

/**
 * 将指定日期变成 YYYYMMDDHHmmss 数字格式
 * @param date
 * @returns
 */
export function toYmdhmsInt(
  date: Date | string | number | null = new Date(),
  deltaDay: number = 0
): number | null {
  const d = dateParse(date)
  if (d == null) return null
  if (deltaDay === 0) {
    return +dateFormat(d, 'YYYYMMDDHHmmss')
  } else {
    return +dateFormat(new Date(d.getTime() + deltaDay * msOfDay), 'YYYYMMDDHHmmss')
  }
}
